package com.jiangjiang.eshop.order.status;

import com.jiangjiang.eshop.order.constant.OrderOperateType;
import com.jiangjiang.eshop.order.dto.OrderInfoDTO;
import com.jiangjiang.eshop.order.service.OrderOperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName LoggedOrderStateMannger
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/24 21:04
 * @Version 1.0
 **/
@Component
public class LoggedOrderStateManager implements OrderStateManager{
    @Autowired
    private OrderStateManagerImpl orderStateManager;
    @Autowired
    private OrderOperateLogService orderOperateLogService;
    @Autowired
    private OrderOperateLogFactory orderOperateLogFactory;

    @Override
    public void create(OrderInfoDTO order) throws Exception {
        orderStateManager.create(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.CREATE_ORDER));
    }

    @Override
    public Boolean canCancel(OrderInfoDTO order) throws Exception {
        return orderStateManager.canCancel(order);
    }

    @Override
    public void cancel(OrderInfoDTO order) throws Exception {
        orderStateManager.cancel(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.CANCEL_ORDER));
    }

    @Override
    public Boolean canPay(OrderInfoDTO order) throws Exception {
        return orderStateManager.canPay(order);
    }

    @Override
    public void pay(OrderInfoDTO order) throws Exception {
        orderStateManager.pay(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.PAY_ORDER));
    }

    @Override
    public void finishDelivery(OrderInfoDTO order) throws Exception {
        orderStateManager.finishDelivery(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.GOODS_DELIVERY));
    }

    @Override
    public Boolean canConfirmReceipt(OrderInfoDTO order) throws Exception {
        return orderStateManager.canConfirmReceipt(order);
    }

    @Override
    public void confirmReceipt(OrderInfoDTO order) throws Exception {
        orderStateManager.confirmReceipt(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.CONFIRM_RECEIPT));
    }

    @Override
    public Boolean canApplyReturnGoods(OrderInfoDTO order) throws Exception {
        return orderStateManager.canApplyReturnGoods(order);
    }

    @Override
    public void applyReturnGoods(OrderInfoDTO order) throws Exception {
        orderStateManager.applyReturnGoods(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.APPLY_RETURN_GOODS));
    }

    @Override
    public void rejectReturnGoodsApply(OrderInfoDTO order) throws Exception {
        orderStateManager.rejectReturnGoodsApply(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.RETURN_GOODS_REJECTED));
    }

    @Override
    public void passedReturnGoodsApply(OrderInfoDTO order) throws Exception {
        orderStateManager.passedReturnGoodsApply(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.RETURN_GOODS_APPROVED));
    }

    @Override
    public void sendOutReturnGoods(OrderInfoDTO order) throws Exception {
        orderStateManager.sendOutReturnGoods(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.SEND_OUT_RETURN_GOODS));
    }

    @Override
    public void confirmReceivedReturnGoods(OrderInfoDTO order) throws Exception {
        orderStateManager.confirmReceivedReturnGoods(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.CONFIRM_RETURN_GOODS_RECEIPT));
    }

    @Override
    public void finishedInputReturnGoods(OrderInfoDTO order) throws Exception {
        orderStateManager.finishedInputReturnGoods(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.FINISHED_RETURN_GOODS_INPUT));
    }

    @Override
    public void finishedRefund(OrderInfoDTO order) throws Exception {
        orderStateManager.finishedRefund(order);
        orderOperateLogService.save(orderOperateLogFactory.get(order, OrderOperateType.FINISHED_RETURN_GOODS_REFUND));
    }
}
